package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.service.AddOneUserService;
import com.zr.service.impl.AddOneUserServiceImpl;

import net.sf.json.JSONObject;

/**
 * 处理添加单个用户请求
 * @author lzq
 *
 */
public class AddOneUserAction extends HttpServlet{
	private AddOneUserService addOneUserService = new AddOneUserServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("utf-8");
		String uname = req.getParameter("uname");
		int rid = Integer.parseInt(req.getParameter("rid"));
		String info = addOneUserService.getAddOneUserByUnameUpseRid(uname, "123456", rid);//设置添加用户默认密码为123456
		PrintWriter pw = resp.getWriter();
		JSONObject json = new JSONObject();
		if("添加成功".equals(info)){
			json.put("success", true);
			json.put("msg", info);
		}else{
			json.put("success", false);
			json.put("msg", info);
		}
		pw.write(json.toString());
		pw.flush();
	}
}
